package com.dwz.test.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dwz.test.vo.Staff;
/**
 * Servlet implementation class Login
 */
public class StaffServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String opt=request.getParameter("opt");
		//登录
		if("login".equals(opt)){
			String id = request.getParameter("id");
			String password = request.getParameter("password");
			
			if("".equals(id)||null==id||"".equals(password)||null==password){
				response.sendRedirect(this.getServletContext().getContextPath()+"/index.jsp");
			}else{
				Staff staff = new Staff();
				staff.setId(id);
				staff.setPassword(password);
				request.getSession().setAttribute("staff", staff);
				response.sendRedirect(this.getServletContext().getContextPath()+"/UIServlet?ui=indexUI");
			}
		}
		//退出
		if("logout".equals(opt)){
			request.getSession().removeAttribute("staff");
			response.sendRedirect(this.getServletContext().getContextPath()+"/index.jsp");
		}
	}
}
